package com.service.Authorization.controller;

import com.service.Authorization.dto.UploadingDto;
import com.service.Authorization.service.VFilePhysicsInfoService;
import com.service.config.utils.RedisUtil;
import com.service.config.utils.Result;
import com.service.config.utils.UserTokenManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 物理文件消息表(VFilePhysicsInfo)表控制层
 *
 * @author makejava
 * @since 2021-05-18 19:56:30
 */
@RestController
@RequestMapping("vFilePhysicsInfo")
@Api(value = "上传logo/文字",produces = "上传logo/文字",tags = "上传logo/文字")
public class VFilePhysicsInfoController {
    /**
     * 服务对象
     */
    @Resource
    private VFilePhysicsInfoService vFilePhysicsInfoService;
    @Resource
    private RedisUtil redisUtil;

    /**
     * 客户方案logo上传
     * @param cloudAuthToken
     * @param file
     * @return
     * @throws Exception
     */
    @ApiOperation(value = " 客户方案图片上传")
    @RequestMapping(value = "uploadServiceLogo", method = RequestMethod.POST)
    @ResponseBody
    public Result uploadServiceLogo(@RequestHeader(value = "cloud-Auth-Token") @ApiParam("token") String cloudAuthToken,
                                    @RequestParam(value = "file",required = false) MultipartFile file,
                                    UploadingDto uploadingDto) throws Exception {
        if (cloudAuthToken != null && !cloudAuthToken.equals("")) {
            String userId = UserTokenManager.getUserId(cloudAuthToken);
            if (!redisUtil.exist(cloudAuthToken + userId)) {
                return Result.failure(10001, "未登录或者用户不存在，请重新登录");
            }
            if (!uploadingDto.getType().equals("3")) {
                return vFilePhysicsInfoService.uploadServiceLogo(uploadingDto,file);
            }
        }
        return Result.ok();
    }
    /**
     * 客户方案文字描述保存
     * @param cloudAuthToken
     * @return
     * @throws Exception
     */
    @ApiOperation(value = " 客户方案文字描述保存")
    @RequestMapping(value = "uploadServiceWord", method = RequestMethod.POST)
    @ResponseBody
    public Result uploadServiceWord(@RequestHeader(value = "cloud-Auth-Token") @ApiParam("token") String cloudAuthToken,
                                    @RequestBody UploadingDto uploadingDto) throws Exception {
        if (cloudAuthToken != null && !cloudAuthToken.equals("")) {
            String userId = UserTokenManager.getUserId(cloudAuthToken);
            if (!redisUtil.exist(cloudAuthToken + userId)) {
                return Result.failure(10001, "未登录或者用户不存在，请重新登录");
            }
            if (uploadingDto.getType().equals("3")) {
                    return vFilePhysicsInfoService.uploadServiceWord(uploadingDto);
            }
        }
        return Result.ok();
    }
}
